package org.example.config;

import lombok.extern.slf4j.Slf4j;
import org.example.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @description: 拦截器配置
 * @author: 谢超
 * @date: 2023/08/13 20:52
 **/
@Configuration
@Slf4j
public class InterceptorConfig implements WebMvcConfigurer {

    private static final String INTERCEPT_PRODUCT = "/api/product/*/**";

    private static final String INTERCEPT_ORDER_PATH = "/api/product_order/*/**";

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                // 添加拦截路径
                .addPathPatterns(INTERCEPT_ORDER_PATH)
                // 排除不拦截
                .excludePathPatterns(INTERCEPT_PRODUCT);
    }
}
